//
//  TestTableViewCell.m
//  10-CustomTableViewCell
//
//  Created by dllo on 16/7/27.
//  Copyright © 2016年 LST. All rights reserved.
//

#import "TestTableViewCell.h"
#import "NewsObject.h"
#define WIDTH self.contentView.frame.size.width
#define HEIGHT self.contentView.frame.size.height
@interface TestTableViewCell ()
@property (nonatomic, strong)UIImageView *image;
@property (nonatomic, strong)UILabel *label1;
@property (nonatomic, strong)UILabel *label2;
@property (nonatomic, strong)UILabel *label3;
@end
@implementation TestTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatSubView];
    }
    return self;
}
- (void)creatSubView {
    _image = [[UIImageView alloc] initWithFrame:CGRectZero];
    //_image.backgroundColor = [UIColor yellowColor];
    [self.contentView addSubview:_image];
    _label1 = [[UILabel alloc] initWithFrame:CGRectZero];
    //_label1.backgroundColor = [UIColor cyanColor];
    [self.contentView addSubview:_label1];
    _label2 = [[UILabel alloc] initWithFrame:CGRectZero];
    //_label2.backgroundColor = [UIColor redColor];
    [self.contentView addSubview:_label2];
    _label3 = [[UILabel alloc] initWithFrame:CGRectZero];
    //_label3.backgroundColor = [UIColor blueColor];
    [self.contentView addSubview:_label3];
 
}
// 有内容/坐标改变时, 会触发该方法
// 1.判断父视图是不是_label2
// 2.改label2的父视图
- (void)layoutSubviews {
    [super layoutSubviews];
//    if (_label2.superview == _label1) {
     CGFloat topMargin = 5;
    CGFloat leftMargin = 5;
    CGFloat rightMargin = 5;
    CGFloat bottomMargin = 5;
    CGFloat heightMargin = 30;
    _image.frame = CGRectMake(leftMargin, topMargin, WIDTH / 3, HEIGHT - leftMargin + rightMargin);
    CGFloat labelX = _image.frame.origin.x + _image.frame.size.width + bottomMargin;
    _label1.frame = CGRectMake(labelX, leftMargin, WIDTH - labelX - rightMargin, heightMargin);
    _label2.frame = CGRectMake(labelX, _label1.frame.size.height + _label1.frame.origin.y + topMargin, _label1.frame.size.width, HEIGHT - _label1.frame.origin.y - heightMargin + leftMargin + rightMargin);
    // label上不要加视图
    CGFloat numberCountx = _label2.frame.size.width * 3/5 - heightMargin;
    CGFloat numberConntHeight = _label2.frame.size.height / 2;
    CGFloat numberCountWidth = _label2.frame.size.width * 2 / 5;
    _label3.frame = CGRectMake(WIDTH - numberCountx, HEIGHT -numberConntHeight - 5, numberCountWidth, numberConntHeight);
   // }
}
- (void)setNewsObject:(NewsObject *)newsObject {
    _newsObject = newsObject;
    _image.image = [UIImage imageNamed:newsObject.newsImage];
    _label1.text = newsObject.newsTitle;
    _label2.text = newsObject.newsDescription;
    _label3.text = newsObject.newsNumberCount;
}
- (void)awakeFromNib {
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
